<!DOCTYPE html>
<html>
<head>
    <title>部门信息管理</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row  layui-col-space10">
        <div class="layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-header">部门信息管理</div>
                <div class="layui-card-body">
                    <table id="dataTable" class="layui-table" lay-filter="layFilter"></table>
                    <!--序号-->
                    <script type="text/html" id="indexTpl">
                        {{d.LAY_TABLE_INDEX+1}}
                    </script>
                    <!--菜单-->
                    <script type="text/html" id="dataTable_toolbar">
                        <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="dataTable_edit"><i class="layui-icon">&#xe642;</i>修改</a>
                        <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="dataTable_pwd"><i class="layui-icon">&#xe642;</i>密码</a>
                    </script>
                    <script type="text/html" id="availableTpl">
                        <input type="checkbox" name="state" value="{{d.id}}" lay-skin="switch" lay-text="解锁|锁定" lay-filter="availableFilter" {{# if(d.state== 1){ }} checked {{# } }}>
                    </script>

                    <!-- 表格头部工具栏 -->
                    <script type="text/html" id="toolbar">
                        <div class="layui-btn-container right">
                            <button lay-event="reload" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe669;</i>重载</button>
                            <button lay-event="add" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe654;</i>新增</button>
                            <button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i>删除</button>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/layui/layui.js" charset="utf-8"></script>
<script>
    layui.extend({
        jmdf: '/modules/jmdf'
        , treeGrid: '/modules/treeGrid/treeGrid'
    }).use(['table', 'form', 'jquery', 'jmdf', 'treeGrid'], function () {
        var $ = layui.jquery, treeGrid = layui.treeGrid, jmdf = layui.jmdf;
        /***********************table表格相关操作 start*************************/
        var tableRenderId = "renderId";
        var tableId = "dataTable";
        var table_layFilter = "layFilter";
        var tableUrl = "listJson";
        var ptable = null;
        //列项内容
        var cols = [[
            {
                width: 220, title: '操作', align: 'center'/*toolbar: '#barDemo'*/
                , templet: function (d) {
                var html = '';
                var addBtn = '<a class="layui-btn layui-btn-xs" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>添加</a>';
                var editBtn = '<a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>';
                var delBtn = '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
                return addBtn + editBtn + delBtn;
            }
            }
            , {field: 'name', width: 300, title: '名称'}
            , {field: 'code', width: 300, title: '编号'}
            , {field: 'sortIndex', width: 300, title: '排序'}
        ]];
        //table设置项
        var options = {
            elem: '#' + tableId//table列表id值
            , url: tableUrl
            , id: tableRenderId
            , cellMinWidth: 120
            , treeId: 'id'//树形id字段名称
            , treeUpId: 'pId'//树形父id字段名称
            , treeShowName: 'name'//以树形式显示的字段
            , cols: cols
            , page: false
        };
        ptable = treeGrid.render(options);
        treeGrid.on('tool(' + table_layFilter + ')', function (obj) {
            var data = obj.data;
            if (obj.event === 'add') {//添加
                var pid = data.id;
                var url = 'form?pid=' + pid;
                jmdf.form(url, "80");
            } else if (obj.event === "edit") {//编辑
                var id = data.id;
                var url = 'form?id=' + id;
                jmdf.form(url, "80");
            } else if (obj.event === "del") {//添加行
                var id = data.id;
                var url = "del?id=" + id;
                jmdf.del(url);
            }
        });

        function loadData() {
            treeGrid.reload(tableRenderId);
        }

        window.loadData = loadData;
    });
</script>
</body>
</html>